import request from '@/modules/index/utils/request';
import qs from "qs";

const store = {
    state: {
        dictNumber: 0,
        currentDirId: 0,
        optionNumber: 0
    },
    mutations: {
        SET_DICT_NUMBER: (state, dictNumber) => {
            state.dictNumber = dictNumber
        },
        SET_CURRENT_DIR_ID: (state, currentDirId) => {
            state.currentDirId = currentDirId
        },
        SET_OPTION_NUMBER: (state, optionNumber) => {
            state.optionNumber = optionNumber
        }
    },
    actions: {
        // 字典列表
        async dictListById(context, params) {
            const data = await request({
                url: `dictionary/getById?${params}`,
                method: 'get'
            });
            return data;
        },
        // 字典分页列表
        async dictPageList(context, params) {
            const data = await request({
                url: params ? `dictionary/pageList?${params}` : 'dictionary/pageList',
                method: 'get'
            });
            return data;
        },
        // 删除字典
        async dictBatchDelete (context, params) {
            const data = await request({
                url: 'dictionary/deleteByIds',
                method: 'post',
                params: params,
                paramsSerializer: (params) => {
                    return qs.stringify(params, { indices: false });
                },
            });
            return data;
        },
        // 选项分页列表
        async optionPageList(context, params) {
            const data = await request({
                url: params ? `dictionaryParam/pageList?${params}` : 'dictionaryParam/pageList',
                method: 'get'
            });
            return data;
        },
        // 选项列表
        async optionListById(context, params) {
            const data = await request({
                url: `dictionaryParam/getById?${params}`,
                method: 'get'
            });
            return data;
        },
        // 删除选项
        async optionBatchDelete (context, params) {
            const data = await request({
                url: 'dictionaryParam/deleteByIds',
                method: 'post',
                params: params,
                paramsSerializer: (params) => {
                    return qs.stringify(params, { indices: false });
                },
            });
            return data;
        },
    }
};

export default store;
